/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution 
{
public:
    long long int preval=-2e12;
    bool isValidBST(TreeNode* root) 
    {
        //if(root->left==nullptr&&root->right==nullptr) return true;
        if(root==nullptr) return true;
        //中序便利
        bool l=isValidBST(root->left);
        if(!l) return false;

        bool ret1=true;
        if(root->val<=preval)
        {
            ret1=false;
        }
         preval=root->val;
        if(ret1==false) return false;
        //如果左树为真才去右树查看
        if(l&&ret1)  return isValidBST(root->right);
        return false;
    }
};